<script setup lang="ts">
import { reactive } from 'vue'

const initForm = {
  name: '',
  gender: '',
  hobbies: [],
  isSchool: false,
  desc: '',
}
const formData = reactive({ ...initForm })

const onSubmit = () => {
  console.log(formData)
}

const onReset = () => {
  Object.assign(formData, { ...initForm })
}
</script>

<template>
  <div>
    <el-form :model="formData" label-width="auto" style="max-width: 600px">
      <el-form-item label="姓名">
        <el-input v-model="formData.name" />
      </el-form-item>
      <el-form-item label="性别">
        <el-select v-model="formData.gender" placeholder="选择性别">
          <el-option label="男" value="male" />
          <el-option label="女" value="female" />
        </el-select>
      </el-form-item>
      <el-form-item label="爱好">
        <el-checkbox-group v-model="formData.hobbies">
          <el-checkbox value="1" name="type"> 唱歌 </el-checkbox>
          <el-checkbox value="2" name="type"> 跳舞 </el-checkbox>
          <el-checkbox value="3" name="type"> 阅读 </el-checkbox>
          <el-checkbox value="4" name="type"> 爬山 </el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="是否上学">
        <el-switch v-model="formData.isSchool" />
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="formData.desc" type="textarea" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
        <el-button @click="onReset">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<style lang="scss" scoped></style>
